Skip to content

Speed up creating filter, function, and test nodes - #5033

Open
Kocal wants to merge 1 commit into
twigphp:3.xfrom
Kocal:perf/shared-name-deprecation
Open

Kocal wants to merge 1 commit into
twigphp:3.xfrom
Kocal:perf/shared-name-deprecation

Conversation

@Kocal

@Kocal Kocal commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Each FilterExpression created 8 identical NameDeprecation('twig/twig', '3.12') objects in its constructor, FunctionExpression created 7, and TestExpression created 4.

The object is immutable, so one instance per class is now shared. This only affects compile time.

new FilterExpression goes from 2136-2175 -> 1517-1525 ns. Compiling a 120-line template with many filters goes from 46.51-47.66 -> 44.40-45.97 ms, and the generated code is identical.

Each `FilterExpression` created 8 identical `NameDeprecation('twig/twig', '3.12')` objects in its constructor, `FunctionExpression` created 7, and `TestExpression` created 4.

The object is immutable, so one instance per class is now shared. This only affects compile time.

`new FilterExpression` goes from 2136-2175 -> 1517-1525 ns. Compiling a 120-line template with many filters goes from 46.51-47.66 -> 44.40-45.97 ms, and the generated code is identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants